import { hp } from '@/utils/util'

const SERVER_PATH = process.env.NUXT_SERVER_PATH
const SERVER_PORT = process.env.NUXT_SERVER_PORT
const BASEURL = SERVER_PATH === 'localhost' ? `http://${SERVER_PATH}:${SERVER_PORT}` : ''

export default $axios => domain => ({
  getByPage (pageNum, pageSize, params) {
    return $axios.$post(`${BASEURL}/authentication-server${domain}/query?type=service&pageNum=${pageNum}&pageSize=${pageSize}`, hp(params))
  },

  getByPageResource (pageNum, pageSize, params) {
    return $axios.$post(`${BASEURL}/authentication-server${domain}/query?type=resource&pageNum=${pageNum}&pageSize=${pageSize}`, hp(params))
  },

  get (id) {
    return $axios.$get(`${BASEURL}/authentication-server${domain}/${id}`)
  },

  add (params) {
    return $axios.$post(`${BASEURL}/authentication-server${domain}`, hp(params))
  },

  update (id, params) {
    return $axios.$put(`${BASEURL}/authentication-server${domain}/${id}`, hp(params))
  },

  del (id) {
    return $axios.$delete(`${BASEURL}/authentication-server${domain}/${id}`)
  },

  toggle (params) {
    return $axios.$post(`${BASEURL}/authentication-server${domain}/toggle`, hp(params))
  }
})
